package goleetcode

import "math"

func modifiedMatrix(matrix [][]int) [][]int {
	res := make([][]int, len(matrix))
	maxAns := getColumnsMax(matrix)
	for i := range res {
		res[i] = make([]int, len(matrix[0]))
	}
	for i := 0; i < len(matrix); i++ {
		for j := 0; j < len(matrix[0]); j++ {
			if matrix[i][j] == -1 {
				res[i][j] = maxAns[j]
			} else {
				res[i][j] = matrix[i][j]
			}
		}
	}
	return res
}

func getColumnsMax(matrix [][]int) []int {
	cols := len(matrix[0])
	res := make([]int, cols)
	for i := range res {
		res[i] = math.MinInt
	}
	for j := 0; j < cols; j++ {
		for _ ,row := range matrix {
			if row[j] > res[j] {
				res[j] = row[j]
			}
		}
	}
	return res
}